@extends('admin::layouts.master')

@section('content')
    <div class="col-lg-12">
        <div class="card card-table">
            <div class="card-header">
                用户管理
                <div class="mt-2">
                    <button type="button" class="btn btn-primary mr-2">用户列表</button>
                    <button data-toggle="modal" data-target="#addUser" type="button" class="btn btn-space btn-primary mt-1">
                        添加用户
                    </button>
                    {{--调用引入组件的模板方法来引入某个组件模板--}}
                    {{--@component第二个参数数组中的键名,会自动的变成变量名,传递到被调用的组件模板中去--}}
                    @component('components.modal',['title' => '添加用户','url' => '/admin/adminuser','id' => 'addUser'])
                        <div class="form-group">
                            <label>登录账号</label>
                            <input type="text" placeholder="请输入后台用户登录账号..." name="name" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>用户昵称</label>
                            <input type="text" placeholder="请输入后台用户昵称..." name="nickname" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>登录密码</label>
                            <input type="password" placeholder="请输入后台用户登录密码..." name="password" class="form-control" required="required">
                        </div>
                    @endcomponent
                    {{--调用引入组件的模板方法来引入某个组件模板--}}
                </div>
            </div>
            <div class="card-body">
                <table class="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>账号</th>
                        <th>昵称</th>
                        <th>创建时间</th>
                        <th class="actions">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($admins as $v)
                        <tr>
                            <td>{{$v['id']}}</td>
                            <td>{{$v['name']}}</td>
                            <td>{{$v['nickname']}}</td>
                            <td>{{$v['created_at']}}</td>
                            <td class="actions">
                                <div class="btn-group btn-space">
                                    <button data-toggle="modal" data-target="#editUser{{$v['id']}}" type="button" class="btn btn-space btn-primary">
                                        编辑
                                    </button>
                                    {{--编辑用户--}}
                                    @component('components.modal',['title' => '编辑用户','url' => '/admin/adminuser/' . $v['id'],'id' => 'editUser' . $v['id'],'method' => 'PUT'])
                                        <div class="form-group text-left">
                                            <label>登录账号</label>
                                            <input type="text" value="{{$v['name']}}" name="name" class="form-control">
                                        </div>
                                        <div class="form-group text-left">
                                            <label>用户昵称</label>
                                            <input type="text" value="{{$v['nickname']}}" name="nickname" class="form-control">
                                        </div>
                                        <div class="form-group text-left">
                                            <label>登录密码</label>
                                            <input type="password" placeholder="请输入后台用户登录密码..." name="password" class="form-control">
                                        </div>
                                    @endcomponent
                                    {{--编辑用户--}}
                                    <form action="/admin/adminuser/{{$v['id']}}" method="post">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-danger">删除</button>
                                    </form>
                                    <a href="{{route ('showRole',$v['id'])}}" class="btn btn-success h-25 ml-1">分配角色</a>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        {{$admins->links()}}
    </div>
@stop
